﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Documents;

namespace JV.Com.Internals
{
    class RichTextBlockExtension
    {
        public static Paragraph GetParagraph(DependencyObject obj)
        {
            return (Paragraph)obj.GetValue(ParagraphProperty);
        }

        public static void SetParagraph(DependencyObject obj, Paragraph value)
        {
            obj.SetValue(ParagraphProperty, value);
        }

        public static readonly DependencyProperty ParagraphProperty =
               DependencyProperty.RegisterAttached("Paragraph", typeof(Paragraph),
               typeof(RichTextBlockExtension), new PropertyMetadata(new Paragraph(), OnParagraphChanged));

        private static void OnParagraphChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var control = sender as RichTextBlock;
            if (control != null)
            {
                control.Blocks.Clear();
                control.Blocks.Add(e.NewValue as Paragraph);
            }
        } 
    }
}
